package com.yqg.protection.listenern;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.yqg.protection.controller.dto.ImportClientDto;
import com.yqg.protection.entity.Client;
import com.yqg.protection.mapper.ClientMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * projectName:xf-service1
 * author:zxf
 * time:2024/10/10 16:10
 * description:
 */
@Component
public class ClientListener extends AnalysisEventListener<ImportClientDto> {

    @Autowired
    ClientMapper clientMapper;

    @Override
    public void invoke(ImportClientDto importClientDto, AnalysisContext analysisContext) {
        Client client = new Client();
        BeanUtil.copyProperties(importClientDto, client, true);
        if (client.getOrganization() == null) {
            client.setOrganization(1l);
        }
        client.setIsDelete(0);
        clientMapper.insert(client);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
